#include "header.h"
using namespace std;
extern ARMY troops[];
extern int hp_status[9][2];
extern TOOLS tools;
extern BASE* Cp[];
extern int board[WIDTH][WIDTH];
extern int STATUS[9][6];
extern DENFEN runMap[WIDTH][WIDTH];

Wnode RunCC()
{
	int a1[8]={-1,0,1,-1,1,-1,0,1},b1[8]={-1,-1,-1,0,0,1,1,1};
	Wnode ansNode;
	ansNode.x=-1;
	bool ans=0;
	int numE=0;
	for(int i=0;i<8;i++)
	{
		if(isEnemy(board[a1[i]+troops[0].pos[0]][b1[i]+troops[0].pos[1]]))
			numE++;
	}
	if(troops[0].hp>300)
		return ansNode;
	bool firstT=0;
	for(int i=0;i<=8;i++)
	{
		if(troops[i].hp>0&&troops[i].active==0)
			continue;
		else if(troops[i].hp>0&&troops[i].active==1)
			firstT=1;
	}
	if(firstT)
		return ansNode;
	if(numE>2)
	{
		priority_queue<Wnode> que;
		Wnode nowP;
		nowP.x=troops[0].pos[0];
		nowP.y=troops[0].pos[1];
		nowP.c=-1;
		que.push(nowP);
		for(int i=1;i<WIDTH-1;i++)
			for(int j=1;j<WIDTH-1;j++)
			{
				if(Cp[0]->move_range[i][j]==1)
				{
					int tp=0;
					for(int k=0;k<=8;k++)
						tp=tp+runMap[i][j].tpHurt[k];
					Wnode tpN;
					tpN.x=i,tpN.y=j;
					tpN.c=RunLim-tp;
					tpN.c=tpN.c+dis(i,j,troops[0].pos[0],troops[0].pos[1]);
				}
			}
		ansNode=que.top();
		return ansNode;
			;
	}
	else
		return ansNode;
}